#include "via.h"

Via::Via()
{
    firstLayerRect = QRectF(-6,-7.5,12,15);
    contactRect = QRectF(-4.5,-4.5,9,9);
    secondLayerRect = QRectF(-8.5,-4.5,17,9);

    viaType = "ODM1";

    setFlag(ItemIsMovable);
}

void Via::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    QBrush brush;
    QPen pen;
    QTransform tr;
    tr.scale(1/(*scale),1/(*scale));
    brush.setTransform(tr);

    if(viaType == "ODM1")
    {
        brush.setColor(QColor(0,0XCC,0x66));
        brush.setStyle(Qt::Dense6Pattern);
        pen.setColor(QColor(0,0XCC,0x66));
        painter->setBrush(brush);
        painter->setPen(pen);

        painter->drawRect(firstLayerRect);

        brush.setColor(Qt::transparent);
        brush.setStyle(Qt::SolidPattern);
        pen.setColor(QColor(0XFF,0xFF,0));
        painter->setBrush(brush);
        painter->setPen(pen);

        painter->drawRect(contactRect);
        painter->drawLine(contactRect.topLeft(),contactRect.bottomRight());
        painter->drawLine(contactRect.bottomLeft(),contactRect.topRight());

        brush.setColor(QColor(0,0X4F,0XFF));
        brush.setStyle(Qt::FDiagPattern);
        pen.setColor(QColor(0,0,0XFF));
        painter->setBrush(brush);
        painter->setPen(pen);

        painter->drawRect(secondLayerRect);
    }

}

QRectF Via::boundingRect() const
{
    return QRectF(-8.5,-7.5,17,15);
}
